package com.shuinfo.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.shuinfo.bean.entity.WechatPacketBind;
import com.shuinfo.dao.WechatPacketBindDao;
import com.shuinfo.service.HzwechatService;
import com.shuinfo.service.WechatPacketBindService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Date;

@Slf4j
@Service
public class WechatPacketBindServiceImpl implements WechatPacketBindService {
    @Resource
    private WechatPacketBindDao hzWechatDao;


    @Override
    public void insert(String openId, String paramId, Integer status, Integer ableStatus) {
        WechatPacketBind wechatPacketBind = new WechatPacketBind();
        wechatPacketBind.setOpenId(openId);
        wechatPacketBind.setParamId(paramId);
        wechatPacketBind.setStatus(status);
        wechatPacketBind.setAbleStatus(ableStatus);
        wechatPacketBind.setCreateTime(new Date());
        int insertResult = hzWechatDao.insert(wechatPacketBind);
        log.info("WechatPacketBindService insert openId:{}, insertResult:{}", openId, insertResult);
    }

    @Override
    public WechatPacketBind detailByParamId(String paramId) {
        QueryWrapper<WechatPacketBind> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("param_id", paramId);
        hzWechatDao.selectOne(queryWrapper);

        return hzWechatDao.selectOne(queryWrapper);
    }

    @Override
    public void updateOpenIdByParamId(String paramId, String openId) {
        WechatPacketBind wechatPacketBind = detailByParamId(paramId);
        wechatPacketBind.setOpenId(openId);
        hzWechatDao.updateById(wechatPacketBind);
    }
}
